package com.monster.servlet.detail;

import com.monster.pojo.Album;
import com.monster.pojo.Song;
import com.monster.service.InfoService;
import com.monster.service.InfoServiceImpl;
import com.monster.service.SongService;
import com.monster.service.SongServiceImpl;
import com.monster.util.DataBaseHtml;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/music/song")
public class SongServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        SongService ss = new SongServiceImpl();
        if (id != null) {
            Long songId = Long.parseLong(id);
            Song song = ss.getSongById(songId);
            song.setProfile(DataBaseHtml.toHtmlProfile(song.getProfile()));
            song.setLyric(DataBaseHtml.toHtmlLyric(song.getLyric()));
            request.setAttribute("song", song);
        }
        request.getRequestDispatcher("song-detail.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
